﻿@page
@model OpenPms.Areas.D.Pages.Setup.RoomTypeModel
@{
    ViewData["Title"] = "房型";
}
<nav aria-label='breadcrumb'>
    <ol class='breadcrumb'>
        
        <li class='breadcrumb-item active' aria-current='page'>
            @ViewBag.Title |
            <a href="javascript:;" onclick="Save()">保存</a> |
            <a href="javascript:;" onclick="Create()" data-bs-title="先保存，后添加" data-bs-toggle="tooltip">添加</a>
        </li>
    </ol>
</nav>


<form method="post" id="FormPost">
    <desk-input-items asp-Items="Items" asp-rowno=1
                      asp-hidden-1=Item.Id asp-hidden-2=Item.HotelId asp-hidden-action="Item.Quantity"
                      asp-for-1=Item.Name
                      asp-for-2=Item.PinYin
                      asp-for-3=Item.Quantity asp-readonly-3=""
                      asp-for-4=Item.IsDelete />
</form>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }
    <script>
        var flag = "@Model.Flag";
        $(function () {
            if (flag == "0")
                ShowToast("保存成功！");
            else if (flag == "1")
                ShowToast("保存并添加成功！");


            $(`input[name$="Name"]`).change(function () {
                var value = $(this).val();
                if (value == "")
                    return;
                var id = $(this).prop("id").replace("_Name", "_PinYin");
                $.get(`/api/pinyin/${value}`, function (ret) {
                    $("#" + id).val(ret);
                });
            });

        });
        function Create() {
            $("#FormPost").attr("action", "@Url.Page("./RoomType")" + "?flag=1");
            $("#FormPost").submit();
        }
        function Save() {
            $("#FormPost").attr("action", "@Url.Page("./RoomType")" + "?flag=0");
            $("#FormPost").submit();
        }
    </script>
}

